import {type HasIdProperty, requestApi, type ResponseBody} from "./api.ts";

export interface TArticle extends HasIdProperty {
    title: string;
    content: string;
    summary: string;
    coverImage: string;
    authorId: number;
    categoryId: number;
    status: string;
    viewCount: number;
    createdAt: string;
    updatedAt: string;
    publishedAt: string;
    tags: ArticleTag[];
}


export interface TArticlePage {
    total: number;
    data: TArticle[];
}


interface ArticleTag {
    articleId: number;
    tagId: number;
}

export function getArticles(pageNumber?: number): ResponseBody<TArticlePage> {
    return pageNumber ? requestApi.get('/article/queryAll/' + pageNumber) : requestApi.get("/article/queryAll")
}


export function getArticle(id: number): ResponseBody<TArticle> {
    return requestApi.get('/article/queryById?id=' + id)
}

export function deleteArticle(id: number): ResponseBody<boolean> {
    return requestApi.delete('/article/delete?id=' + id);
}
